package jsd2204.bookstore.bookserver.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jsd2204.bookstore.bookserver.pojo.dto.ConsumeDTO;
import jsd2204.bookstore.bookserver.pojo.entity.User;
import jsd2204.bookstore.bookserver.pojo.vo.BookStandardVO;
import jsd2204.bookstore.bookserver.service.impl.BookServiceImpl;
import jsd2204.bookstore.bookserver.service.impl.UserServiceImpl;
import jsd2204.bookstore.bookserver.web.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author jiale
 * @version 1.0
 * @description这是用户的一个控制类
 * @date 2022/08/01 22:17
 **/
@Api(tags = "用户管理模块")
@Slf4j
@RestController
public class UserController {
    @Autowired
    private UserServiceImpl userService;

    @GetMapping("/buyBook")
    @ApiOperation("消费业务")
    @ApiOperationSupport(order = 100)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "money", value = "书籍的价格", dataType = "Double", required = true)
    })
    public JsonResult<Void> buyBook(Double money, Long id,HttpSession session) {
        User user = new User();
        user.setId(2L)
                .setAsset(1500.0)
                .setNick("小米")
                .setPhoto("rrrrr")
                .setEmail("55555@qq.com");
        session.setAttribute("user", user);
        userService.buyBook(money,id,session);
        return JsonResult.ok();
    }
}
